using System.Collections.Generic;
using System.Linq;

namespace Citi.Scheduler.Domain
{
    public partial class Library 
    {
        public IEnumerable<Library> GetLibrariesByCategoryAndType(int categoryId, LibraryType type)
        {
            return SelectAll<Library>().Where(x=> GetLibrariesByType(type).Contains(x)
                && x.LibraryVersions.Any(y=> y.Routines.Any(w=> w.CategoryId == categoryId)));
        }

        public IEnumerable<Library> GetLibrariesByType(LibraryType type)
        {
            return SelectAll<Library>().Where(x => x.LibraryVersions.Any(y => y.Type == (int)type));
        }
    }
}
